﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace ExoticCarRental
{
    public partial class reservation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserSettings"] == null)
            {
                Response.Redirect("login.aspx");
            }

            string email = Request.Cookies["UserSettings"]["email"];
            if (!IsPostBack)
            {
                BusinessLayer bl = new BusinessLayer();
                DataTable dt = bl.GetCategories();
                cboCategories.DataSource = dt;
                cboCategories.DataTextField = "category_name";
                cboCategories.DataValueField = "category_id";
                cboCategories.DataBind();
                string category_id;
                category_id = Request.QueryString["cp"].ToString();
                cboCategories.Items.FindByValue(category_id).Selected = true;

                dt = bl.GetLocations();
                cboLocations.DataSource = dt;
                cboLocations.DataTextField = "addr";
                cboLocations.DataValueField = "location_id";
                cboLocations.DataBind();

                txtEmailAddress.Text = email;

                
                               
            }

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            int reservation_id = bl.CreateReservation(txtEmailAddress.Text, 
                                                txtLastName.Text, 
                                                txtFirstName.Text, 
                                                PickUpDate.Date,
                                                DropOffDate.Date, 
                                                Convert.ToInt32(cboLocations.SelectedValue.ToString()),
                                                Convert.ToInt32(cboCategories.SelectedValue.ToString()), 
                                                txtCardNo.Text, 
                                                cboCreditCardType.SelectedValue.ToString(),
                                                Convert.ToInt32(cboCardMonth.SelectedValue.ToString()),
                                                Convert.ToInt32(cboCardYear.SelectedValue.ToString()));


            Response.Redirect("reservation-confirmation.aspx?id=" + reservation_id.ToString());
        }

        
       

        

 
    }
}
